<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="include.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>共享的文件</title>
<script src="js/metroui/js/jquery.dataTables.min.js"></script>
</head>
<body>
<h2>共享的文件</h2>
<p class="text-accent">此处列出其他用户共享的文件，若下载失败则可能是文件不存在或其他用户未开放该文件的下载权限。</p>

<div class="input-control text" data-role="input" style="float:right;">
<input type="text" name="search" id="extra_search"><button class="button"><span class="mif-search"></span></button>
</div>
<table class="table striped hovered dataTable border bordered" id="dataTables-1" style="width:100%;">
                <thead>
                <tr>
                    <th class="text-left">Fileid</th>
                    <th class="text-left">Filename</th>
					<th class="text-left">Uploadtime</th>
					<th class="text-left">Operation</th>
                </tr>
                </thead>

                <tbody>
                </tbody>
            </table>
<script type="text/javascript">
 $(document).ready(function(){
	
	 function ChangeSearch(){
		   var ss=$("#extra_search").val();
			table1.ajax.url(encodeURI("shared.action?search="+ss)).load();
	   }
	 


	$("#extra_search").blur(function(){
	
		ChangeSearch();      		    
});
	$("#extra_search").focus(function(){
		$("#extra_search").keydown(function(e){ 
			if(e.keyCode==13){ 
				ChangeSearch();
			}
			
		});
		
	});
	 
	 var table1=$("#dataTables-1").DataTable( {
	        "processing": true,
	        "ordering": false, 
	        "searching":false,
	        serverSide: true,
	        ajax:{
				url:"shared.action"
				//"type": "GET"
				//data:"search="+$("#extra_search").val()
				},
	     
	        	//dataSrc: 'result'

	    	"oLanguage": {
	    		"sLengthMenu": "每页显示 _MENU_ 条记录",
	    		"sZeroRecords": "抱歉， 没有找到",
	    		"sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条",
	    		"sInfoEmpty": "没有数据",
	    		"sInfoFiltered": "(从 _MAX_ 条数据中检索)",
	    		"oPaginate": {
	    		"sFirst": "首页",
	    		"sPrevious": "前一页",
	    		"sNext": "后一页",
	    		"sLast": "尾页"
	    		},
	    		"sZeroRecords": "没有检索到数据"
	    	},
	    	
	    	
	    columns: [ 
	    	{data:"fileid"},
	    	
	    	{data:"filename"},
	    	{data:"uploadtime.time",render:function(data){
	    		
	    		return UnixToDate(data);
	    	}
	    	},
	    	{"defaultContent":"<button class='button primary'>下载</button>"}
	    	]

		 }
	    );
	 $('#dataTables-1 tbody').on('click', '.primary', function () {

    	 var id=$(this).parent().parent().children("td").get(0).innerHTML; 

    	 window.location.href=encodeURI("downloadShared.action?fileid="+id);
    	 
    	 
    } );
	 
 });
 
 
 
 function UnixToDate(unixTime) {
     var date=new Date(unixTime);
     Y = date.getFullYear() + '-';
     M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
     D = date.getDate() + ' ';
     h = date.getHours() + ':';
     m = date.getMinutes() + ':';
     s = date.getSeconds(); 
 	
     return Y+M+D+h+m+s;
 }
	 </script>
            
</body>
</html>